package com.mydemo.springlearning.functions.mail_send.service;

import com.mydemo.springlearning.functions.mail_send.entity.Mail;
import com.mydemo.springlearning.functions.mail_send.utils.MailUtil;
import com.mydemo.springlearning.common.entity.ResponseCode;
import com.mydemo.springlearning.common.entity.ServerResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MailTestServiceImpl implements MailTestService {
    @Autowired
    private MailUtil mailUtil;


    @Override
    public ServerResponse testIdempotence() {
        return ServerResponse.success("testIdempotence:success——token合法");
    }

    @Override
    public ServerResponse accessLimit() {
        return ServerResponse.success("accessLimit: success");
    }

    @Override
    public ServerResponse send(Mail mail) {
        log.info("收到消息: {}", mail.toString());
        boolean success = mailUtil.send(mail);
        return ServerResponse.success(success ? ResponseCode.MAIL_SEND_SUCCESS.getMsg() : ResponseCode.ERROR.getMsg());
    }

}
